package com.tsing.mapper.impl;

import com.tsing.common.framwork.mapper.CommonDao;
import com.tsing.mapper.CollectMapper;

import java.sql.SQLException;

/**
 * @auth 卢孝宇
 * @date 2023/12/13 22:20
 */
public class CollectMapperImpl extends CommonDao implements CollectMapper{

    @Override
    public Integer collectCount(Integer userId, Long postId) {
        Integer list = null;

        Object[] params = {userId,postId};
        try {
            list = executeCount( "select count(*) from tl_collect where userId = ? and postId = ?", params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public Integer add(Integer userId, Integer postId) {
        Integer list = null;

        Object[] params = {userId,postId};
        try {
            list = executeUpdate("insert into tl_collect(userId,postId) values(?,?)",params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public Integer delete(Integer userId, Integer postId) {
        Integer list = null;

        Object[] params = {userId,postId};
        try {
            list = executeUpdate("delete from tl_collect where userId = ? and postId = ?",params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
